package cn.onein.edu.backend.service.impl;

import java.util.Date;
import java.util.List;

import cn.onein.edu.backend.dao.DailyUserActionsDao;
import cn.onein.edu.backend.service.DailyUserActionsService;
import cn.onein.edu.backend.vo.DailyAcitonMailVO;
import cn.onein.edu.biz.bean.User;
import cn.onein.edu.biz.bean.UserAction;

public class DailyUserActionsServiceImpl implements DailyUserActionsService {
	private DailyUserActionsDao dailyUserActionsDao;

	public void setDailyUserActionsDao(DailyUserActionsDao dailyUserActionsDao) {
		this.dailyUserActionsDao = dailyUserActionsDao;
	}

	@Override
	public void initUserShadow() {
		dailyUserActionsDao.initUserShadow();
	}

	@Override
	public List<User> doDailyUserActions(int maxPerTa) {
		// 取得未处理用户列表
		List<User> list = dailyUserActionsDao.getUnCompletedUserList(maxPerTa);

		if (list != null && list.size() > 0) {
			// 用户每日行动指南数据处理
			list = dailyUserActionsDao.doDailyUserActions(list);

			// 更新指定的UserShadow的Completed = true
			dailyUserActionsDao.setUserShadowCompleted(list);
		}

		return list;
	}

	@Override
	public DailyAcitonMailVO getDailyActionByUserIDAndDate(Long userid,	Date actionDate) {
		UserAction userAction = dailyUserActionsDao.getUserActionByUQKey(userid, actionDate);
		
		DailyAcitonMailVO dailyAcitonMailVO = null;
		if(userAction != null){
			dailyAcitonMailVO = dailyUserActionsDao.getDailyActionById(userAction.getDailyActionId());
			// 用户当天的会员服务是否有效
			dailyAcitonMailVO.setActive(userAction.getActive());
		}
		 
		return dailyAcitonMailVO;
	}
}
